package com.lax.advertserver.service.sys.impl;

import com.lax.advertserver.bean.sys.UserInfo;
import com.lax.advertserver.bo.sys.UserInfoBo;
import com.lax.advertserver.dao.sys.UserInfoMapper;
import com.lax.advertserver.exception.AdsException;
import com.lax.advertserver.exception.AdsExprInfo;
import com.lax.advertserver.service.sys.UserInfoService;
import com.lax.advertserver.utils.IDUtils;
import org.dozer.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;

    /**
     * 新增用户信息
     *
     * @param userInfoBo
     * @return
     */
    @Override
    public UserInfoBo insertUserInfo(UserInfoBo userInfoBo) throws AdsException {
        UserInfoBo bo = new UserInfoBo();
        bo.setUserName(userInfoBo.getUserName());
        List<UserInfoBo> userInfoBos = userInfoMapper.getUserInfoByParam(bo);
        if (userInfoBos.size() > 0) {
            throw AdsException.instance(AdsExprInfo.USER_EXIST);
        }
        userInfoBo.setId(IDUtils.uuid2());
        userInfoMapper.insert(userInfoBo);
        return userInfoBo;
    }
}
